package io.israel.asher;

import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

/**
 * @author imlij
 */
@Slf4j
@EnableBatchProcessing
@SpringBootApplication
public class IsraelAsherApplication {

	private JobBuilderFactory jobBuilderFactory;

	private StepBuilderFactory stepBuilderFactory;

	@Bean
	public Tasklet tasklet() {
		return (contribution, context) -> {
			log.info("Israel Asher");
			return RepeatStatus.FINISHED;
		};
	}

	@Bean
	public Job job(Step step) {
		return jobBuilderFactory.get("job1").start(step).build();
	}

	@Bean
	public Step step(Tasklet tasklet) {
		return stepBuilderFactory.get("step1").tasklet(tasklet).build();
	}

	public static void main(String[] args) {
		System.exit(SpringApplication.exit(SpringApplication.run(IsraelAsherApplication.class, args)));
	}


	@Autowired
	public void setJobBuilderFactory(JobBuilderFactory jobBuilderFactory) {
		this.jobBuilderFactory = jobBuilderFactory;
	}

	@Autowired
	public void setStepBuilderFactory(StepBuilderFactory stepBuilderFactory) {
		this.stepBuilderFactory = stepBuilderFactory;
	}
}
